package com.cicoding.service.impl;


import com.cicoding.domian.KufangData;
import com.cicoding.service.KufangService;
import com.cicoding.utlis.JdbcUtils;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

@Service
public class KufangServiceImpl implements KufangService {


    @Override
    public List<KufangData> getKufangData() {
        try {
            return   query();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
      //  return kufangxinxiMapper.getFangData();
    }

    public  List<KufangData> query() throws Exception {
        Connection conn = JdbcUtils.getConnect();
        Statement stat = conn.createStatement();
        ResultSet rs = stat.executeQuery("select * from kufangxinxi");
        List<KufangData> list = new ArrayList<>();
        while (rs.next()) {
            KufangData kufangData = new KufangData();
            kufangData.setId(rs.getInt("id"));
            kufangData.setName(rs.getString("name"));
            kufangData.setCode(rs.getString("code"));
            list.add(kufangData);
        }
        JdbcUtils.close(conn, rs);
        return list;
    }

}
